package com.tenbent.product.base.mapper;

import java.util.List;
import java.util.Map;

import com.tenbent.product.base.bo.BizObject;
import com.tenbent.product.base.exception.TenbentException;
import com.tenbent.product.base.template.CrudTemplate;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.springframework.stereotype.Repository;

/**
 * 
 * 所有的Mapper继承这个接口（BaseSqlMapper继承SqlMapper，对Mapper进行接口封装）
 *
 * 说明：此接口是mybaties基类接口，mybatis会生成Proxy类，所以不能给@Repository(value="XXXX")起名字
 *
 * 在service中根据名字找不到此接口的实现类，实现类是动态生成，只能通过类型自动注入。在注入配置上也的注意
 *
 * mybatis配置的basePackageScan路径
 * 
 * @author Randy Yan
 *
 *         Created by ThinkPad on 2017/7/25.
 * 
 */
@Repository
public interface BaseSqlMapper<T> extends SqlMapper {

	@InsertProvider(type = CrudTemplate.class, method = "insert")
	@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
	void add(T entity) throws Exception;

	@InsertProvider(type = CrudTemplate.class, method = "insertContainPk")
	@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
	void addContainPk(T entity) throws Exception;

	@UpdateProvider(type = CrudTemplate.class, method = "update")
	void update(T entity) throws Exception;

	@DeleteProvider(type = CrudTemplate.class, method = "delete")
	void delete(T entity) throws Exception;

	@DeleteProvider(type = CrudTemplate.class, method = "deleteLogic")
	void deleteLogic(T entity) throws Exception;

	@SelectProvider(type = CrudTemplate.class, method = "getByKey")
	Map<String, Object> getByKey(T entity) throws Exception;

	@SelectProvider(type = CrudTemplate.class, method = "getAll")
	List<Map<String, Object>> getAll(Class<? extends BizObject> clazz) throws Exception;

	@SelectProvider(type = CrudTemplate.class, method = "queryByObj")
	List<Map<String, Object>> queryByObj(T entity) throws TenbentException;

	@SelectProvider(type = CrudTemplate.class, method = "queryByMap")
	List<Map<String, Object>> queryByMap(Map<String, Object> paramMap) throws TenbentException;

	@SelectProvider(type = CrudTemplate.class, method = "getMaxKey")
	Map<String, Object> getMaxKey(Class<? extends BizObject> clazz) throws Exception;

}
